﻿using System;
using System.Collections;
using TaoLeH.Helper;
using TaoLeH.Helper.Json;

namespace TaoLeH.Models.Dto
{
    /// <summary>
    /// api请求上下文
    /// 作者：leev
    /// 时间：2018-12-18
    /// </summary>
    public class ApiContext
    {
        public ApiContext()
        { }

        public ApiHttpRequest ApiHttpReq { get; set; }


        /// <summary>
        /// base64解密后data
        /// </summary>
        public string DecData { get; set; }

        /// <summary>
        /// 商户md5签名key
        /// </summary>
        public string MerKey { get; set; }


        public ApiHttpResponse ApiHttpResp { get; set; }

        public string ReturnResp()
        {
            //data内容base64
            if (!string.IsNullOrEmpty(ApiHttpResp.Data))
                ApiHttpResp.Data = ApiHelper.EncodeBase64(ApiHttpResp.Data);
            //md5签名
            Hashtable ht = ModelHandler<ApiHttpResponse>.TransforClass(ApiHttpResp);
            string sign = ApiHelper.CreateSign(ht, MerKey);
            ApiHttpResp.Sign = sign;

            string resp = JsonHelper.Serialize(ApiHttpResp);
            //LogHelper.Info("thirdapi统一请求返回:", resp);
            return resp;
        }
    }
}
